package com.zz.shop.common;

public class ResponseResult<T> {
    private int code;

    private String msg;
    //保存成功后获得到的数据
    private T t;
    public static ResponseResult createSuccess(){
        return new ResponseResult(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMsg());
    }
    public static ResponseResult createSuccess(String msg){
        return new ResponseResult(ResponseCode.SUCCESS.getCode(), msg);
    }
    public static ResponseResult createSuccess(int code,String msg){
        return new ResponseResult(code, msg);
    }
    public static <T> ResponseResult createSuccess(T data){
        return new ResponseResult(ResponseCode.FAIL.getCode(),ResponseCode.SUCCESS.getMsg(),data);
    }


    public static ResponseResult createFail(){
        return new ResponseResult(ResponseCode.FAIL.getCode(), ResponseCode.FAIL.getMsg());
    }

    @Override
    public String toString() {
        return "ResponseResult{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", t=" + t +
                '}';
    }

    public static ResponseResult createFail(String msg){
        return new ResponseResult(ResponseCode.FAIL.getCode(), msg);
    }
    public static ResponseResult createFail(int code,String msg){
        return new ResponseResult(code, msg);
    }
    public static <T> ResponseResult createFail(T data){
        return new ResponseResult(ResponseCode.FAIL.getCode(),ResponseCode.FAIL.getMsg(),data);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getT() {
        return t;
    }

    public void setT(T t) {
        this.t = t;
    }

    public ResponseResult() {
    }

    public ResponseResult(T t) {
        this.t = t;
    }

    public ResponseResult(int code, T t) {
        this.code = code;
        this.t = t;
    }

    public ResponseResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResponseResult(int code) {
        this.code = code;
    }

    public ResponseResult(String msg) {
        this.msg = msg;
    }

    public ResponseResult(int code, String msg, T t) {
        this.code = code;
        this.msg = msg;
        this.t = t;
    }
}
